﻿namespace Rosieks.Web.Flow
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
using System.Web.Mvc;

    public class LambdaCondition<TWebflowModel> : ITransitionCondition
    {
        private Func<TWebflowModel, ControllerContext, bool> condition;

        public LambdaCondition(Func<TWebflowModel, ControllerContext, bool> condition)
        {
            this.condition = condition;
        }

        public bool IsValid(System.Web.Mvc.ControllerContext context)
        {
            var webflowModel = (TWebflowModel)WebflowContext.GetCurrent(context.HttpContext).Model;

            return this.condition(webflowModel, context);
        }
    }
}
